package com.viphuli.adapter;

import java.util.List;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;

import com.offroader.utils.ViewUtils;
import com.viphuli.app.R;
import com.viphuli.fragment.PurchaseOrderFillFragment;
import com.viphuli.http.bean.part.HomeRoomServiceItem;
import com.viphuli.util.ImageUtils;

public class NurseListViewAdapter extends BaseAdapter {

	private Activity act;
	private List<HomeRoomServiceItem> list;

	public NurseListViewAdapter(Activity act, List<HomeRoomServiceItem> list) {
		this.act = act;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int index) {
		return list.get(index);
	}

	@Override
	public long getItemId(int index) {
		return index;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;

		if (convertView == null || convertView.getTag() == null) {
			convertView = ViewUtils.inflateView(parent.getContext(), R.layout.listview_home_service_nurse_item);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		//填充数据
		final HomeRoomServiceItem item = list.get(position);

		ImageUtils.load(holder.img, item.getIcon());
		holder.title.setText(item.getName());
		holder.desc.setText(item.getDesc());
		holder.duration.setText(item.getDuration());
		holder.price.setText(item.price());

		//事件绑定
		holder.orderBtn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View view) {
				PurchaseOrderFillFragment.go(act, item.getServiceItemId(), item.getServiceType(), item.getName());
			}
		});

		return convertView;
	}

	protected class ViewHolder {
		@Bind(R.id.id_main_home_service_item_img)
		ImageView img;
		@Bind(R.id.id_main_home_service_item_title)
		TextView title;
		@Bind(R.id.id_main_home_service_item_desc)
		TextView desc;
		@Bind(R.id.id_main_home_service_item_service_duration)
		TextView duration;
		@Bind(R.id.id_main_home_service_item_price)
		TextView price;
		@Bind(R.id.id_main_home_service_item_order_btn)
		TextView orderBtn;

		public ViewHolder(View view) {
			ButterKnife.bind(this, view);
		}
	}

}
